home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Misc / OfMiceAndMen / Source / MaView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  3.3 KB  |  145 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "MaView.h"
  5. #import <dpsclient/wraps.h>
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #import <dpsclient/dpsclient.h>
  9.  
  10. @implementation MaView
  11.  
  12. #define        DESSINE    1
  13. #define        EFFACE        0
  14.  
  15.  
  16. -initFrame:(const NXRect *) framerect
  17. {
  18.     [super initFrame:framerect];
  19.     action = EFFACE ;
  20.     return self;
  21. }
  22.  
  23. - (int) dessine:(int)nombre:(int)nbrIter:(int)coul:(float ) p:(float *)abscisses: (float *)ordonnees
  24. {
  25.     int k,m,mg;
  26.     float xx[NBRMAX],yy[NBRMAX];
  27.     if( nombre == 0 ) 
  28.         return 0 ;
  29.     couleur = coul;
  30.     pas_de_calcul = p;
  31.     nombre_de_souris = nombre ;
  32.     if (nbrIter>NBRITER)
  33.         nombre_iterations = NBRITER ;
  34.     else     nombre_iterations = nbrIter;
  35.     for( m=0 ; m<nombre ; m++ )
  36.         {
  37.         souris[m][0].x = abscisses[m];
  38.         souris[m][0].y = ordonnees[m];
  39.         }
  40.     for( k=0 ; k<nbrIter ; k++ )
  41.         {
  42.         for (m=0;m<nombre;m++)
  43.             {
  44.             mg = (m+1) % nombre;
  45.             xx[m] = souris[m][k].x+p*(souris[mg][k].x-souris[m][k].x);
  46.             yy[m] = souris[m][k].y+p*(souris[mg][k].y-souris[m][k].y);
  47.             }
  48.         for (m=0;m<nombre;m++)
  49.             {
  50.             souris[m][k+1].x = xx[m];
  51.             souris[m][k+1].y = yy[m];
  52.             }    
  53.         }
  54.     action = DESSINE ;
  55.     [self display];    
  56.     return nombre;
  57. }
  58.  
  59. - efface:sender
  60. {
  61.     action = EFFACE ;
  62.     nombre_de_souris = 0;
  63.     [self display];
  64.     return self;
  65. }
  66.  
  67. -drawSelf:(NXRect *)rects :(int)rectCount
  68. {
  69.     float maxX , maxY ;
  70.     float minX , minY ;
  71.     float coefX , coefY ;
  72.     int i,k;
  73.     float X,Y,Z,inverse;
  74.     float rougeDebut, vertDebut, bleuDebut;
  75.     float rougeFin, vertFin, bleuFin;
  76.     float r,v,b;
  77.     
  78.     NXConvertColorToRGB([couleurFond color],&rougeFin,&vertFin,&bleuFin);
  79.     PSsetrgbcolor(rougeFin, vertFin, bleuFin);
  80.     NXRectFill(&bounds);
  81.     if( action == DESSINE )
  82.         {
  83.         maxX = minX = souris[0][0].x ;
  84.         maxY = minY = souris[0][0].y ;
  85.         for (k=0;k<nombre_de_souris;k++)
  86.             {
  87.             for( i=0 ; i<nombre_iterations ; i++ )
  88.                 {
  89.                 if( souris[k][i].x < minX ) minX = souris[k][i].x ;
  90.                     else if( souris[k][i].x > maxX )  maxX= souris[k][i].x ;
  91.                 if( souris[k][i].y < minY ) minY = souris[k][i].y ;
  92.                     else if( souris[k][i].y > maxY ) maxY = souris[k][i].y ;
  93.                 }
  94.             }
  95.             
  96.         if (fabs(coefX = fabs(maxX - minX)) < 1e-6) coefX = 1.0;
  97.         if (fabs(coefY = fabs(maxY - minY)) < 1e-6) coefY = 1.0;
  98.  
  99.         printf("%f,%f\n", NX_WIDTH(&bounds) ,NX_HEIGHT(&bounds));
  100.         
  101.         NXConvertColorToRGB([couleurFin color],&rougeFin,&vertFin,&bleuFin);
  102.         NXConvertColorToRGB([couleurDebut color],&rougeDebut,&vertDebut,&bleuDebut);
  103.         r = (rougeFin-rougeDebut)/nombre_iterations;
  104.         v = (vertFin-vertDebut)/nombre_iterations;
  105.         b = (bleuFin-bleuDebut)/nombre_iterations;
  106.         inverse = 1.0/(float)nombre_iterations;
  107.  
  108.         PSsetlinewidth(1.0);
  109.         for (k=0;k<nombre_de_souris;k++)
  110.             {
  111.             X = (souris[k][0].x-minX)* NX_WIDTH(&bounds) / coefX;
  112.             Y = (souris[k][0].y-minY)* NX_HEIGHT(&bounds) / coefY;
  113.             for( i=1 ; i<nombre_iterations ; i++)
  114.                 {
  115.                 switch(couleur)
  116.                 {
  117.                 case 1:    Z = 1.0-pow((float)i*inverse,0.166666666);
  118.                         PSsetgray(Z);
  119.                         break;
  120.                 case 2:    Z = pow((float)i*inverse,3.0);
  121.                         PSsetgray(Z);
  122.                         break;
  123.                 case 3 :    PSsetrgbcolor(rougeDebut+r*i,vertDebut+v*i,bleuDebut+b*i);
  124.                         break;
  125.                 default:    PSsetgray(NX_WHITE);
  126.                 }
  127.                 PSnewpath();        
  128.                 PSmoveto(X,Y);
  129.                 X = (souris[k][i].x-minX)* NX_WIDTH(&bounds) / coefX;
  130.                 Y = (souris[k][i].y-minY)* NX_HEIGHT(&bounds) / coefY;
  131.                 PSlineto( X , Y ) ;
  132.                 PSstroke();    
  133.                 }
  134.             }
  135.         }
  136.     else
  137.         {
  138.         }    
  139.     
  140.     return self;
  141. }
  142.  
  143.  
  144. @end
  145.